'''
Created on 5 mai 2010

@author: philip
'''

from django.db import models
from djangotoolbox.fields import BlobField
from django.utils.simplejson.decoder import JSONDecoder
from django.utils.simplejson.encoder import JSONEncoder

class Image(models.Model):
    picture = BlobField()
    smallThumb = BlobField()
    mediumThumb = BlobField()
    
class Photo(models.Model):
    # possible values: flickr | kavadenn
    community_id = models.CharField(max_length=50)
    source = models.CharField(max_length=50)
    thumb_url = models.CharField(max_length=50)
    medium_url = models.CharField(max_length=50)
    original_url = models.CharField(max_length=50)
    title = models.CharField(max_length=50)
    #serialized meta data for the image 
    #DO NOT USE directly, call meta instead 
    meta_raw = models.CharField(max_length=100)
    def getMeta(self):
        return JSONDecoder().decode(self.meta_raw)
    def setMeta(self,meta):
        self.meta_raw = JSONEncoder().encode(meta)
    meta = property(getMeta,setMeta)
    added = models.DateTimeField(auto_now_add=True)
    
class PhotoNotification(models.Model):
    NOTIFICATION_ADDED = "added"
    
    community_id = models.CharField(max_length=50)
    photo = models.ForeignKey(Photo)
    # possible values: added
    notification = models.CharField(max_length=50)
    added = models.DateTimeField(auto_now_add=True)